home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBButton / Button.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  7.2 KB  |  229 lines

  1. //    Button.cpp : Defines the initialization routines for the DLL and the exported functions
  2. //        High Tech BASIC, Copyright (C) TransEra Corp 1999, All Rights Reserved.
  3.  
  4. #include "stdafx.h"
  5. #include "Button.h"
  6. #include "ButtonDlg.h"
  7. #include "DialogThread.h"
  8. #include "assert.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16.  
  17.  
  18. //
  19. //    Note!
  20. //
  21. //        If this DLL is dynamically linked against the MFC
  22. //        DLLs, any functions exported from this DLL which
  23. //        call into MFC must have the AFX_MANAGE_STATE macro
  24. //        added at the very beginning of the function.
  25. //
  26. //        For example:
  27. //
  28. //        extern "C" BOOL PASCAL EXPORT ExportedFunction()
  29. //        {
  30. //            AFX_MANAGE_STATE(AfxGetStaticModuleState());
  31. //            // normal function body here
  32. //        }
  33. //
  34. //        It is very important that this macro appear in each
  35. //        function, prior to any calls into MFC.  This means that
  36. //        it must appear as the first statement within the 
  37. //        function, even before any object variable declarations
  38. //        as their constructors may generate calls into the MFC
  39. //        DLL.
  40. //
  41. //        Please see MFC Technical Notes 33 and 58 for additional
  42. //        details.
  43. //
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CButtonApp
  47.  
  48. BEGIN_MESSAGE_MAP(CButtonApp, CWinApp)
  49.     //{{AFX_MSG_MAP(CButtonApp)
  50.         // NOTE - the ClassWizard will add and remove mapping macros here.
  51.         //    DO NOT EDIT what you see in these blocks of generated code!
  52.     //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CButtonApp construction
  57.  
  58. CButtonApp::CButtonApp()
  59. {
  60.     // TODO: add construction code here,
  61.     // Place all significant initialization in InitInstance
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // The one and only CButtonApp object
  66.  
  67. CButtonApp theApp;
  68.  
  69.  
  70. //****************************************************************************************************
  71. // begin global variables -- used to communicate between threads and different instances of classes
  72.  
  73.  
  74. ButtonDlg * g_pBtnDlg = NULL;            // global pointer to button dialog used for setting focus and closing
  75. short g_BtnCount;                                // the number of buttons desired
  76. long g_Width;                                    // width of the dialog box
  77. OPTION g_Option;                                // 1 for modal, 2 for threaded variable update, 3 for threaded with signals
  78. CString g_Title;                                // Window title
  79. CString    g_Description;                            // Text above buttons will wrap to two lines if too long
  80. CString    g_Text[10];                                // button text
  81. short * g_pPress;                                // pointer into HTBasic memory for updateing user input
  82.  
  83.  
  84. //    end global variables
  85. //***************************************************************************************************
  86. //  begin global functions not exported
  87.  
  88.  
  89. // Initialize is used to set the member variables of a ButtonDlg instance to
  90. // the settings saved from the user input.  Globals were used because this
  91. // function might be called from the main thread or the spawned thread.
  92.  
  93. //void Initialize(ButtonDlg * Bdlg)
  94. //{    Bdlg->g_BtnCount = g_BtnCount;
  95. //    Bdlg->g_Width = g_Width;
  96. //    Bdlg->m_option = g_Option;
  97. //    Bdlg->m_sTitle = g_Title;
  98. //    Bdlg->m_sStaticText = g_Text0;
  99. //    Bdlg->m_sBtnText[0] = g_Text1;
  100. //    Bdlg->m_sBtnText[1] = g_Text2;
  101. //    Bdlg->m_sBtnText[2] = g_Text3;
  102. //    Bdlg->m_sBtnText[3] = g_Text4;
  103. //    Bdlg->m_sBtnText[4] = g_Text5;
  104. //    Bdlg->m_sBtnText[5] = g_Text6;
  105. //    Bdlg->m_sBtnText[6] = g_Text7;
  106. //    Bdlg->m_sBtnText[7] = g_Text8;
  107. //    Bdlg->m_sBtnText[8] = g_Text9;
  108. //    Bdlg->m_sBtnText[9] = g_Text10;
  109. //    Bdlg->m_pPress = g_Press;
  110. //    g_pBtnDlg = Bdlg;                            // save pointer to dialog so we can get to it later no matter what thread.
  111.  
  112. //}
  113.  
  114.  
  115. // end global functions not exported
  116. //*****************************************************************************************************
  117. // begin exported functions
  118.  
  119.  
  120. // Showbutton is the main function for setting up and displaying the button dialog box.  
  121. //    Params:
  122. //        option is a value between 1 and MAXOPTION.  a 1 will call a modal dialog box suspending Program execution and returning
  123. //                the number of the button pushed or a zero if the dialog is closed with no button push.
  124. //        count is the number of buttons from 0 to MAXBUTTON
  125. //        width is the desired width of the dialog window and buttons
  126. //        title is the text for the window title
  127. //        description is the text that will appear above the buttons
  128. //        text1 - text10 is the button text
  129. //        press is a pointer to a short in Basic memory used as an alternative for the return value.
  130.  
  131. short Showbutton(short option,short count,long width,char * title,char * description,char * text1,char * text2,char * text3
  132.              ,char * text4,char * text5,char * text6,char * text7,char * text8,char * text9,char * text10,short * press)
  133. {    AFX_MANAGE_STATE(AfxGetStaticModuleState());
  134.  
  135.     long result = 0;
  136.  
  137.     if (g_pBtnDlg != NULL)                        // Button dialog already active
  138.     {    return((short)result);
  139.     }
  140.  
  141.     if (count < 0 || count > MAXBUTTON)
  142.     {    g_BtnCount = 0;                            // default to 0 buttons for bad input
  143.     }
  144.     else
  145.     {    g_BtnCount = count;                        // save number of buttons
  146.     }
  147.  
  148.     g_Width = width;                            // save width
  149.  
  150.     if (option < 1 || option > MAXOPTION)
  151.     {    g_Option = modal;                        // default to modal for bad input
  152.     }
  153.     else
  154.     {    g_Option = (OPTION)(option);            // 1 = modal  
  155.     }                                            // 2 = threaded with variable
  156.                                                 // 3 = threaded with signal
  157.  
  158.  
  159.     g_Title = title;
  160.     g_Description = description;
  161.     g_Text[0] = text1;
  162.     g_Text[1] = text2;
  163.     g_Text[2] = text3;
  164.     g_Text[3] = text4;
  165.     g_Text[4] = text5;
  166.     g_Text[5] = text6;
  167.     g_Text[6] = text7;
  168.     g_Text[7] = text8;
  169.     g_Text[8] = text9;
  170.     g_Text[9] = text10;
  171.  
  172.     g_pPress = press;                            // save pointer to press
  173.     
  174.     switch (g_Option)
  175.     {    case modal:
  176.         {    ButtonDlg Btn;                        // create dialog object
  177. //            Initialize(&Btn);                    // set member functions to user specified values
  178.             g_pBtnDlg = &Btn;
  179.             result = Btn.DoModal();    
  180.             g_pBtnDlg = NULL;                    // reset pointer to dialog
  181.             break;
  182.         }
  183.         
  184.         case variable:
  185.         case signal:
  186.         {    CWinThread * pThread = AfxBeginThread(RUNTIME_CLASS (DialogThread));    // create thread to execute dialog
  187.             result = 1;
  188.             break;
  189.         }
  190.  
  191.         default:
  192.             assert(0);
  193.             break;
  194.     }
  195.  
  196.     return((short)result);
  197. }
  198.  
  199.  
  200. // end Showbutton
  201. //*****************************************************************************************
  202. // Setfocus -- used to bring the button dialog box to the foreground and activate.
  203.  
  204.  
  205. void Setfocus()
  206. {    if (g_pBtnDlg != NULL)
  207.     {    SetForegroundWindow(g_pBtnDlg->m_hWnd);        // bring window to foreground and activate
  208.     }
  209. }
  210.  
  211.  
  212. // end Setfocus
  213. //*****************************************************************************************
  214. // Closebutton -- Used to close button dialog box when running in its own thread.
  215.  
  216.  
  217. void Closebutton()
  218. {    if (g_pBtnDlg != NULL)
  219.     {    g_pBtnDlg->KillTimer(1);                // stop timer from updating dialog
  220.         g_pBtnDlg->EndDialog(0);                // close dialog and allow spawned thread to run out
  221.         g_pBtnDlg = NULL;                        // reset pointer to dialog
  222.         //Sleep(0);                                // This line allows the thread to shut down before Basic regains control
  223.     }
  224. }
  225.  
  226.  
  227. // end Closebutton
  228. //*****************************************************************************************
  229.